/**
 * class that represents a IP v4 address
 */
#ifndef WII_GI_C_IPV4_ADDRESS_H
#define WII_GI_C_IPV4_ADDRESS_H

#include <network.h>

namespace wiigi
{
   /**
    * Small helper class for managing IPv4 addresses
    */
   class c_IPv4_Address
   {
      public:
         
         /**
          * Method to return reference to this wii IP address
          *
          * @retval Returns instances of this class that represents our IP address
          */
         static c_IPv4_Address& getLocalAddress( void )
         {
            return m_LocalAddress;
         }
         
         /**
          * Method to set our IP address
          *
          * @retval 
          */
         static void setLocalAddress( c_IPv4_Address& Address )
         {
            m_LocalAddress = Address;
            
            return;
         }
          
         /**
          * Default constructor
          */
         c_IPv4_Address()
         {
            m_Address.s_addr = 0; //Sets up invalid address
            return;
         }
         
         /**
          * overloaded constructor.
          *
          * @param AddressStr e.g, 192.168.1.1
          */
         c_IPv4_Address( const char* AddressStr )
         {
            if( inet_aton(AddressStr, &m_Address) == 0 )
            {
               m_Address.s_addr = 0; //Just in case
            }
               
            return;
         }
         
         /**
          * overloaded constructor. 
          * 
          * @param Address 0xC0A80101
          */
         c_IPv4_Address( u32 Address )
         {
            m_Address.s_addr = Address;
            return;
         }
         
         /**
          * Checks if this address is valid
          *
          * retval true if valid, false if not
          */
         bool checkValid( void ) const
         {
            return getIntegerAddress() ? true : false;
         }
         
         /**
          * returns the 32bit integer version of network address
          *
          * @retval integer representation of address
          */
         u32 getIntegerAddress( void ) const
         {
            return m_Address.s_addr;
         }
                  
      protected:
         
         struct in_addr m_Address;
         
         static c_IPv4_Address m_LocalAddress;
   };
   
   
}

#endif //WII_GI_C_IPV4_ADDRESS_H
